package kt.com.bilin.coin.ui.activity

import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.RecyclerView
import com.alibaba.android.arouter.facade.annotation.Route
import com.bilin.coin.R
import com.bilin.coin.databinding.ItemMyMessageBinding
import com.bilin.coin.databinding.ItemMyPrizeBinding
import kotlinx.android.synthetic.main.activity_base_refresh.*
import kt.com.bilin.coin.api.API_SERVICE
import kt.com.bilin.coin.api.toData
import kt.com.bilin.coin.bean.LotteryBean
import kt.com.bilin.coin.common.PATH_MY_PRIZE
import kt.com.bilin.coin.common.getString
import kt.com.bilin.coin.ui.adapter.BaseRecyclerAdapter
import kt.com.bilin.coin.ui.adapter.BaseViewHolder

@Route(path = PATH_MY_PRIZE)
class MyPrizeActivity : BaseRefreshActivity<LotteryBean>() {
    override fun initView() {
        titleView.titleStr = R.string.text_my_prize.getString()
        mBaseRecyclerAdapter = MyPrizeAdapter()
        super.initView()
        recyclerView.addItemDecoration(DividerItemDecoration(this,DividerItemDecoration.VERTICAL))
    }

    override fun onReload() {
        launchUI({ API_SERVICE.lotteryPage(mRefreshHelper.page).toData()?.records }, mRefreshHelper.handApiObserver())
    }

    inner class MyPrizeAdapter : BaseRecyclerAdapter<BaseViewHolder<ItemMyPrizeBinding>, LotteryBean>() {
        override fun onCreateViewHolder(parent: ViewGroup, p1: Int) = BaseViewHolder(ItemMyPrizeBinding.inflate(getLayoutInflate(parent.context), parent, false))
        override fun onBindViewHolder(holder: BaseViewHolder<ItemMyPrizeBinding>, bean: LotteryBean, position: Int) {
            holder.mViewBinding.run {
                bean.run {
                    tvTitle.text = awardDesc
                    tvTime.text = createTime
                    setViewClick(position, root)
                }
            }
        }
    }
}